﻿<Page
    x:Name="pageRoot"
    x:Class="Fabrikam.Client.ItemsPage"
    DataContext="{Binding Source={StaticResource ItemsPageViewModel}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Fabrikam.Client"
    xmlns:data="using:Fabrikam.Client.Data"
    xmlns:common="using:Fabrikam.Client.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:conv="using:Fabrikam.Client.Converters"
    xmlns:controls="using:Fabrikam.Client.Controls"
    mc:Ignorable="d">

    <Page.Resources>
        <conv:ColorLevelConverter x:Key="ColorLevelConverter" />
        <conv:DateTimeConverter x:Key="DateTimeConverter" />
        <conv:BooleanToVisibilityConverter Inverted="True" x:Key="VisibleIfTrueConverter" />
    </Page.Resources>

    <Page.BottomAppBar>
        <CommandBar>
            <CommandBar.PrimaryCommands>
                <AppBarButton x:Uid="Add" Icon="Add" Label="Add" Command="{Binding AddCommand}" />
                <AppBarButton x:Uid="Sync" Icon="Sync" Label="Sync" Command="{Binding SyncCommand}" />
            </CommandBar.PrimaryCommands>
        </CommandBar>
        
    </Page.BottomAppBar>
    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Background="#585858">
        <Grid.ChildrenTransitions>
            <TransitionCollection>
                <EntranceThemeTransition/>
            </TransitionCollection>
        </Grid.ChildrenTransitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Image Stretch="Uniform" Source="Assets/StartScreenBottom.png" Grid.Row="1" IsHitTestVisible="False"
						VerticalAlignment="Bottom" HorizontalAlignment="Left"  />

        <Image Stretch="None" Source="Assets/StartScreenUpRight.png" Grid.Row="0"
						VerticalAlignment="Top" HorizontalAlignment="Right"  />

        <!-- Horizontal scrolling grid -->
        <GridView
            x:Name="itemGridView"
            AutomationProperties.AutomationId="ItemsGridView"
            AutomationProperties.Name="Items"
            TabIndex="1"
            Grid.RowSpan="2"
            Padding="116,136,116,46"
            ItemsSource="{Binding ServiceTickets}"
            SelectionMode="None"
            IsSwipeEnabled="false"
            IsItemClickEnabled="True"
            ItemClick="ItemView_ItemClick">
            <GridView.ItemTemplate>
                <DataTemplate>
                    <Grid HorizontalAlignment="Left" Width="250" Height="250">
                        <Border Background="{Binding ServiceTicket.StatusValue, Converter={StaticResource ColorLevelConverter}}">
                            <Image x:Name="itemImage" Source="{Binding Image}" Grid.Row="1" Grid.Column="2" />
                        </Border>
                        <StackPanel VerticalAlignment="Bottom" Background="{ThemeResource ListViewItemOverlayBackgroundThemeBrush}">
                            <TextBlock Text="{Binding ServiceTicket.Title}" Foreground="{ThemeResource ListViewItemOverlayForegroundThemeBrush}" Style="{StaticResource BaseTextBlockStyle}" Height="60" Margin="15,0,15,0" FontWeight="SemiBold"/>
                            <TextBlock Text="{Binding ServiceTicket.Opened, Converter={StaticResource DateTimeConverter}}" 
                                       Foreground="{ThemeResource ListViewItemOverlaySecondaryForegroundThemeBrush}" 
                                       Style="{StaticResource BaseTextBlockStyle}" 
                                       TextWrapping="NoWrap" Margin="15,0,15,10" FontSize="12"
                                       HorizontalAlignment="Right"
                                       
                                       />
                        </StackPanel>
                    </Grid>

                </DataTemplate>
            </GridView.ItemTemplate>
        </GridView>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Margin="39,59,39,0" Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
                        Style="{StaticResource NavigationBackButtonNormalStyle}"
                        VerticalAlignment="Top"
                        AutomationProperties.Name="Back"
                        AutomationProperties.AutomationId="BackButton"
                        AutomationProperties.ItemType="Navigation Button"/>
            <TextBlock x:Name="pageTitle" Text="{StaticResource AppName}" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1" 
                        IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,30,40"/>
        </Grid>

        <controls:WaiterControl IsInProgress="{Binding IsSyncing}" Background="Black" Grid.RowSpan="2" />
        
    </Grid>
</Page>
